<?php

namespace App\Http\Controllers\Mapi;
use App\Http\Controllers\Controller;
use App\Http\Validators\BeatValidator;
use App\Services\BeatService;
use App\Services\RhymeService;
use Illuminate\Http\Request;
use App\Api\Helper\ReturnMessage;
use Illuminate\Support\Facades\Cache;

class BeatController extends Controller
{

    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name Beat 详情接口
     * @user IHammer
     */
    public function BeatInfo(Request $request){
        $res = BeatService::BeatInfoHandle($request);
        return ReturnMessage::successArrayToApp($res);
    }

    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name 音乐点击量 - 也放这里了
     * @user IHammer
     */
    public function MusicClick(Request $request){
        $request->offsetSet("type",'music');
        $errmsg = "操作失败";
        $res = BeatService::BeatClickHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }
    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name  Beat 增加点击量
     * @user IHammer
     */
    public function BeatClick(Request $request){
        $request->offsetSet("type",'beat');
        $errmsg = "操作失败";
        $res = BeatService::BeatClickHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }
    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name Beat 列表数据
     * @user IHammer
     */
    public function BeatLists(Request $request){
        $res = BeatService::BeatListsHandle($request);
        return ReturnMessage::successLists($res);
    }
    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name 创建
     * @user IHammer
     */
    public function BeatCreate(Request $request){
        BeatValidator::create($request);
        $errmsg = "操作失败";
        $res = BeatService::BeatCreateHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }

    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name Beat 删除
     * @user IHammer
     */
    public function BeatDelete(Request $request){
        $errmsg = "操作失败";
        $res = BeatService::BeatDeleteHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }

}
